<template>
  <div class="duty_check">
    <van-tabs
      class="cont-tab"
      v-model="activeName"
      :sticky="true"
      line-width="35"
      line-height="2"
      title-active-color="#d80a06"
      title-inactive-color="#333333"
      border
      swipeable
      @click="tabsClick">
      <van-tab title="脱岗核查" name="3"></van-tab>
      <van-tab title="旷工核查" name="4"></van-tab>
    </van-tabs>
    <div class="switch_title">
      <van-dropdown-menu>
        <van-dropdown-item
          @change="statusChange"
          title-class="time_title"
          v-model="selectData.status"
          :options="statusOption" />
      </van-dropdown-menu>
      <div>
        <span class="operate_tips">批量操作：</span>
        <span @click="subAll(2)" class="col_btn_r">确认{{ titleName }}</span>
        <span @click="subAll(1)" class="col_btn_r">未{{ titleName }}</span>
      </div>
    </div>
    <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="getPageList">
      <div class="list_con_main" v-if="ExtraParmas.length">
        <div class="check_left">
          全选：
          <van-checkbox v-model="checkedAll" :disabled="checkALL" @change="checkAll" shape="square"></van-checkbox>
        </div>
        <div v-for="item in ExtraParmas" :key="item.id">
          <div class="duty_one">
            <div class="duty_one_left">
              <van-checkbox :disabled="item.checkStatus !== '0'" v-model="item.checked" shape="square"></van-checkbox>
              <div class="iconfont icontouxiang6"></div>
              <div class="top_left_name1">{{ item.userName }}</div>
              <div class="top_left_nam2">{{ item.orgName }}</div>
            </div>
            <div v-if="item.checkStatus == '0'">
              <span class="col_btn_main m-bbb-r" @click="onCancelTop(item, 2)">确认{{ titleName }}</span>
              <span class="col_btn_main" @click="onCancelTop(item, 1)">未{{ titleName }}</span>
            </div>
            <span v-else :class="item.checkStatus == '1' ? 'check_no' : 'check_yes'">{{ item.checkStatusName }}</span>
          </div>
          <div class="spot_list_tip">
            <div class="time">
              {{ titleName }}时间:{{ moment(item.startTime).format('YYYY-MM-DD HH:mm') }}至{{
                moment(item.endTime).format('HH:mm')
              }}({{ item.hours }})
            </div>
          </div>
        </div>
      </div>
      <van-empty v-if="ExtraParmas.length == 0" description="暂无数据" />
    </van-list>
  </div>
</template>

<script>
import { getOverseerList, checkOverseerStatus } from '@api/api-attendance.js'
import moment from 'moment'
export default {
  name: 'DutyInspect',
  components: {},
  props: {
    showDuCha: {
      type: String,
      default: '1',
    },
  },
  data() {
    return {
      moment: moment,
      activeName: '3',
      titleName: '脱岗',
      ExtraParmas: [],
      loading: false,
      finished: false,
      sticky: false,
      selectData: {
        status: '',
      },
      tablePage: {
        currentPage: 1,
        pageSize: 10,
        totalSize: 0,
      },
      statusOption: [],
      leaveList1: [
        { value: '', text: '全部' },
        { value: '1', text: '未脱岗' },
        { value: '2', text: '脱岗' },
      ],
      leaveList2: [
        { value: '', text: '全部' },
        { value: '1', text: '未旷工' },
        { value: '2', text: '旷工' },
      ],
      checkedAll: false,
      resultList: [],
      checkALL: false,
    }
  },
  created() {
    if (this.$route.query.twoTabs) {
      this.activeName = this.$route.query.twoTabs
    }
    if (this.activeName == '3') {
      this.statusOption = [...this.leaveList1]
      this.titleName = '脱岗'
    } else {
      this.statusOption = [...this.leaveList2]
      this.titleName = '旷工'
    }
  },
  mounted() {},
  methods: {
    getPageList() {
      //获取已申报列表
      this.loading = true
      this.finished = false
      getOverseerList({
        currentPage: this.tablePage.currentPage,
        pageSize: this.tablePage.pageSize,
        param: {
          startTime: '',
          endTime: '',
          checkType: this.activeName,
          checkStatus: this.selectData.status,
        },
      })
        .then(res => {
          if (res.status == 200) {
            this.ExtraParmas.push(...res.data.content)
            for (let i in this.ExtraParmas) {
              this.$set(this.ExtraParmas[i], 'checked', false)
            }
            this.checkALL = true
            for (let i in this.ExtraParmas) {
              if (this.ExtraParmas[i].checkStatus == '0') {
                this.checkALL = false
                break
              }
            }
            this.tablePage.totalSize = res.data.totalSize
            this.tablePage.currentPage++
            this.loading = false
            if (this.ExtraParmas.length === this.tablePage.totalSize) {
              this.finished = true
            }
          }
        })
        .catch(err => {
          this.loading = false
          this.finished = true
        })
    },
    //数据
    statusChange() {
      this.tablePage.currentPage = 1
      this.tablePage.pageSize = 10
      this.ExtraParmas = []
      this.getPageList()
    },
    tabsClick() {
      this.checkedAll = false
      if (this.activeName == '3') {
        this.statusOption = [...this.leaveList1]
        this.titleName = '脱岗'
      } else {
        this.statusOption = [...this.leaveList2]
        this.titleName = '旷工'
      }
      this.selectData.status = ''
      this.statusChange()
    },
    //全选
    checkAll() {
      for (let i in this.ExtraParmas) {
        this.$nextTick(() => {
          if (this.ExtraParmas[i].checkStatus == '0') {
            this.ExtraParmas[i].checked = this.checkedAll
          }
        })
      }
    },
    //确认脱岗、未脱岗
    subAll(types) {
      this.resultList = []
      this.ExtraParmas.forEach(element => {
        if (element.checkStatus == '0' && element.checked) {
          this.resultList.push(element.id)
        }
      })

      if (this.resultList.length == 0) {
        this.$toast.fail('请选择需要提交的数据')
        return
      }
      checkOverseerStatus({
        idList: this.resultList,
        checkStatus: types,
      }).then(res => {
        if (res.status == 200) {
          this.$toast.success(res.message)
          this.statusChange()
        }
      })
    },
    //单个确认
    onCancelTop(row, types) {
      checkOverseerStatus({
        idList: [row.id],
        checkStatus: types,
      }).then(res => {
        if (res.status == 200) {
          this.$toast.success(res.message)
          if (types == '1') {
            row.checkStatus = '1'
            row.checkStatusName = `未${this.titleName}`
          } else if (types == '2') {
            row.checkStatus = '2'
            row.checkStatusName = `${this.titleName}`
          }
        }
      })
    },
  },
}
</script>

<style lang="scss" scoped>
.duty_check {
  font-size: 12px;
  .switch_title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 36px;
    background-color: #f4f6f8;
    position: relative;
    padding-left: 6px;
    /deep/.van-dropdown-menu {
      margin-right: 10px;
      .van-dropdown-menu__bar {
        height: 36px;
        background-color: transparent;
        box-shadow: none;
        .time_title {
          font-size: 12px;
          color: #333333;
        }
      }
      .van-popup--top {
        position: absolute;
      }
      .van-dropdown-item {
        position: absolute;
        top: 36px !important;
        height: 500px;
        width: 100%;
        .van-dropdown-item__content {
          max-height: 50%;
        }
      }
    }
    .col_btn_r {
      padding: 4px 6px;
      background-color: #1989fa;
      color: #fff;
      margin-right: 6px;
      border-radius: 2px;
      font-size: 12px;
    }
  }
  .list_con_main {
    padding: 0 10px;
    .check_left {
      display: flex;
      padding: 5px 0;
      /deep/.van-checkbox__icon {
        font-size: 14px;
      }
    }
    .col_btn_main {
      padding: 3px 5px;
      background-color: #a57d60;
      color: #fff;
      border-radius: 2px;
      font-size: 12px;
    }
    .check_no {
      color: #27b345;
    }
    .check_yes {
      color: #ff0000;
    }
    .m-bbb-r {
      margin-right: 6px;
    }
    .icontouxiang6 {
      font-size: 18px;
      color: #666;
      margin: 0 6px;
    }
    .duty_one_left {
      display: flex;
      align-items: center;
      .top_left_nam2 {
        color: #969799;
        margin-left: 5px;
      }
    }
    .duty_one {
      display: flex;
      justify-content: space-between;
      align-items: center;
      height: 25px;
      margin: 5px 0;
      /deep/.van-checkbox__icon {
        font-size: 14px;
      }
    }
    .list_con_text {
      font-size: 13px;
      font-weight: bold;
      color: #333;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .spot_list_type {
      font-size: 13px;
      color: #e67f2b;
      padding: 5px 5px;
      display: flex;
      justify-content: center;
      align-items: center;
      min-width: 65px;
    }
    .spot_list_tip {
      display: flex;
      justify-content: space-between;
      align-items: center;
      font-size: 12px;
      border-bottom: 1px solid #efefef;
      padding-bottom: 10px;
      .list_tip {
        height: 40px;
        background-color: #fdf1dd;
        border-radius: 2px;
        display: flex;
        justify-content: center;
        align-items: center;
        margin-right: 10px;
        padding: 10px;
      }
    }
  }
}
</style>
